package com.zenchn.dynamic;

import static com.zenchn.dynamic.TMiCustomerUpgradeDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.zenchn.model.TMiCustomerUpgrade;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface TMiCustomerUpgradeDynamicMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    BasicColumn[] selectList = BasicColumn.columnList(upgradeId, customerId, beforeLevel, upgradeLevel, creator, upgradeType, createTime, isEnable);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<TMiCustomerUpgrade> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    @InsertProvider(type=SqlProviderAdapter.class, method="insertMultiple")
    int insertMultiple(MultiRowInsertStatementProvider<TMiCustomerUpgrade> multipleInsertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("TMiCustomerUpgradeResult")
    Optional<TMiCustomerUpgrade> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="TMiCustomerUpgradeResult", value = {
        @Result(column="upgrade_id", property="upgradeId", jdbcType=JdbcType.CHAR, id=true),
        @Result(column="customer_id", property="customerId", jdbcType=JdbcType.CHAR),
        @Result(column="before_level", property="beforeLevel", jdbcType=JdbcType.INTEGER),
        @Result(column="upgrade_level", property="upgradeLevel", jdbcType=JdbcType.INTEGER),
        @Result(column="creator", property="creator", jdbcType=JdbcType.CHAR),
        @Result(column="upgrade_type", property="upgradeType", jdbcType=JdbcType.CHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="is_enable", property="isEnable", jdbcType=JdbcType.CHAR)
    })
    List<TMiCustomerUpgrade> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, TMiCustomerUpgrade, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, TMiCustomerUpgrade, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    default int deleteByPrimaryKey(String upgradeId_) {
        return delete(c -> 
            c.where(upgradeId, isEqualTo(upgradeId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    default int insert(TMiCustomerUpgrade record) {
        return MyBatis3Utils.insert(this::insert, record, TMiCustomerUpgrade, c ->
            c.map(upgradeId).toProperty("upgradeId")
            .map(customerId).toProperty("customerId")
            .map(beforeLevel).toProperty("beforeLevel")
            .map(upgradeLevel).toProperty("upgradeLevel")
            .map(creator).toProperty("creator")
            .map(upgradeType).toProperty("upgradeType")
            .map(createTime).toProperty("createTime")
            .map(isEnable).toProperty("isEnable")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    default int insertMultiple(Collection<TMiCustomerUpgrade> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, TMiCustomerUpgrade, c ->
            c.map(upgradeId).toProperty("upgradeId")
            .map(customerId).toProperty("customerId")
            .map(beforeLevel).toProperty("beforeLevel")
            .map(upgradeLevel).toProperty("upgradeLevel")
            .map(creator).toProperty("creator")
            .map(upgradeType).toProperty("upgradeType")
            .map(createTime).toProperty("createTime")
            .map(isEnable).toProperty("isEnable")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    default int insertSelective(TMiCustomerUpgrade record) {
        return MyBatis3Utils.insert(this::insert, record, TMiCustomerUpgrade, c ->
            c.map(upgradeId).toPropertyWhenPresent("upgradeId", record::getUpgradeId)
            .map(customerId).toPropertyWhenPresent("customerId", record::getCustomerId)
            .map(beforeLevel).toPropertyWhenPresent("beforeLevel", record::getBeforeLevel)
            .map(upgradeLevel).toPropertyWhenPresent("upgradeLevel", record::getUpgradeLevel)
            .map(creator).toPropertyWhenPresent("creator", record::getCreator)
            .map(upgradeType).toPropertyWhenPresent("upgradeType", record::getUpgradeType)
            .map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
            .map(isEnable).toPropertyWhenPresent("isEnable", record::getIsEnable)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    default Optional<TMiCustomerUpgrade> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, TMiCustomerUpgrade, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    default List<TMiCustomerUpgrade> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, TMiCustomerUpgrade, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    default List<TMiCustomerUpgrade> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, TMiCustomerUpgrade, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    default Optional<TMiCustomerUpgrade> selectByPrimaryKey(String upgradeId_) {
        return selectOne(c ->
            c.where(upgradeId, isEqualTo(upgradeId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, TMiCustomerUpgrade, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    static UpdateDSL<UpdateModel> updateAllColumns(TMiCustomerUpgrade record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(upgradeId).equalTo(record::getUpgradeId)
                .set(customerId).equalTo(record::getCustomerId)
                .set(beforeLevel).equalTo(record::getBeforeLevel)
                .set(upgradeLevel).equalTo(record::getUpgradeLevel)
                .set(creator).equalTo(record::getCreator)
                .set(upgradeType).equalTo(record::getUpgradeType)
                .set(createTime).equalTo(record::getCreateTime)
                .set(isEnable).equalTo(record::getIsEnable);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(TMiCustomerUpgrade record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(upgradeId).equalToWhenPresent(record::getUpgradeId)
                .set(customerId).equalToWhenPresent(record::getCustomerId)
                .set(beforeLevel).equalToWhenPresent(record::getBeforeLevel)
                .set(upgradeLevel).equalToWhenPresent(record::getUpgradeLevel)
                .set(creator).equalToWhenPresent(record::getCreator)
                .set(upgradeType).equalToWhenPresent(record::getUpgradeType)
                .set(createTime).equalToWhenPresent(record::getCreateTime)
                .set(isEnable).equalToWhenPresent(record::getIsEnable);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    default int updateByPrimaryKey(TMiCustomerUpgrade record) {
        return update(c ->
            c.set(customerId).equalTo(record::getCustomerId)
            .set(beforeLevel).equalTo(record::getBeforeLevel)
            .set(upgradeLevel).equalTo(record::getUpgradeLevel)
            .set(creator).equalTo(record::getCreator)
            .set(upgradeType).equalTo(record::getUpgradeType)
            .set(createTime).equalTo(record::getCreateTime)
            .set(isEnable).equalTo(record::getIsEnable)
            .where(upgradeId, isEqualTo(record::getUpgradeId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_mi_customer_upgrade")
    default int updateByPrimaryKeySelective(TMiCustomerUpgrade record) {
        return update(c ->
            c.set(customerId).equalToWhenPresent(record::getCustomerId)
            .set(beforeLevel).equalToWhenPresent(record::getBeforeLevel)
            .set(upgradeLevel).equalToWhenPresent(record::getUpgradeLevel)
            .set(creator).equalToWhenPresent(record::getCreator)
            .set(upgradeType).equalToWhenPresent(record::getUpgradeType)
            .set(createTime).equalToWhenPresent(record::getCreateTime)
            .set(isEnable).equalToWhenPresent(record::getIsEnable)
            .where(upgradeId, isEqualTo(record::getUpgradeId))
        );
    }
}